package kr.hayarobee.jaringobi.model;

import java.util.ArrayList;
import java.util.List;

import kr.hayarobee.jaringobi.model.account.Account;


public class Bill {
	
	private List<Account> fromAccounts;
	private List<Account> toAccounts;

	public Bill() {
		this.fromAccounts = new ArrayList<Account>();
		this.toAccounts = new ArrayList<Account>();
	}

	public void from(Account ...accounts) {
		for (Account from : accounts) {
			this.fromAccounts.add(from);
		}
	}

	public void to(Account ...accounts) {
		for (Account to : accounts) {
			this.toAccounts.add(to);
		}
	}

	public boolean isValidate() {
		int totalFrom = getTotal(this.fromAccounts);
		int totalTo = getTotal(this.toAccounts);
		return totalFrom == totalTo;
	}

	private int getTotal(List<Account> accounts) {
		int result = 0;
		for (Account account : accounts) {
			result += account.checkBalance();
		}
		return result;
	}

}
